<?php


namespace app\app\controller;


class Recommend extends Base
{
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 去掉电视直播的选项
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function indexV1()
    {
        $page = input('page', 0, 'intval');
        if ($page < 1) {
            $page = 1;
        }

        $data = cache('TuijianNew_list_pagev1_' . $page);
        if (empty($data)) {
            $tuijians = [];
            $list = db('recommend')->where('is_show', 1)->order('sort', 'asc')->where('id','<>',23)->order('time_added', 'desc')->order(
                'id',
                'desc'
            )->paginate(3);
//                dump($data);
            foreach ($list as $tuijian) {
                $tuijian['xilie_name'] = $tuijian['name'];
                $tuijian['xilie_content'] = $tuijian['content'];
                $tuijian['xilie_id'] = $tuijian['id'];
                $tuijian['vod_pic_slide'] = $tuijian['fengmian'];
                $tuijian['list'] = db('recommend_vod')->alias('rv')->join(
                    '__VOD__ v',
                    'v.vod_id=rv.vod_id',
                    'LEFT'
                )->where(
                    'rv.recommend_id',
                    $tuijian['id']
                )->where('v.vod_id', '>', 0)->field(
                    'v.vod_name,v.vod_pic,v.vod_pic_thumb,v.image_down,v.vod_pic_slide,v.vod_blurb,v.vod_remarks,v.vod_id,v.vod_level,v.vod_actor,v.vod_class,v.vod_time,rv.sort_manual,rv.sort'
                )->order('rv.sort_manual', 'asc')->order('rv.sort', 'asc')->order('rv.time_added', 'desc')->order('rv.id', 'desc')->limit(
                    0,
                    $tuijian['limit']
                )->select();
                foreach ($tuijian['list'] as &$litem) {
                    if ($litem['image_down'] > 0) {
                        $litem['vod_pic'] = 'http://7dfjeh.aojiasen.cn/cover/' . $litem['vod_id'] . '.jpg';
                    }
                }
//                    dump($tuijian);
                $tuijians[] = $tuijian;
            }
            $data = [];
            $data['list'] = $tuijians;
            $data['lastPage'] = $list->lastPage();
            $data['currentPage'] = $list->currentPage();
            $data['listRows'] = $list->listRows();
            cache('TuijianNew_list_pagev1_' . $page, $data, 1200);
        }
        $host = request()->host();
        if (in_array($host, [ 'www.hawen.online'])) {
            foreach ($data['list'] as &$dataListItem) {
                $dataListItem['xilie_name'] = "苹果用户商店搜索《千文影视》[支持iPad 视频秒播]\n安卓用户点击右上角分享下载新版本 [视频秒播]";
                $dataListItem['name'] = "苹果用户商店搜索《千文影视》 [支持iPad 视频秒播]\n安卓用户点击右上角分享下载新版本 [视频秒播]";
            }
        }

        $this->success('获取成功', $data);
    }

}